/**
 * @file encoder_logger.h
 * @author your name (you@domain.com)
 * @brief 简单的日志宏
 * @version 0.1
 * @date 2025-01-13
 * 
 * @copyright Copyright (c) 2025
 * 
 */
#ifndef ENCODER_LOGGER_H
#define ENCODER_LOGGER_H
#include <stdio.h>
#include <time.h>
#include <stdint.h>
#include <string.h>

#define LOG_LEVEL_DEBUG "DEBUG"
#define LOG_LEVEL_INFO "INFO"
#define LOG_LEVEL_WARN "WARN"
#define LOG_LEVEL_ERROR "ERROR"

#define GET_CURRENT_TIME(time_str) do { \
    time_t now; \
    struct tm *tm_info; \
    time(&now); \
    tm_info = localtime(&now); \
    strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", tm_info); \
} while (0)

#define DEBUG_LOG(format, ...) do {                                                                         \
    char time_str[80] = {0};                                                                                \
    GET_CURRENT_TIME(time_str);                                                                             \
    char *filename = strrchr(__FILE__, '/') + 1;                                                              \
    printf("%s [%s] [%s:%d]:" format "\n", time_str, LOG_LEVEL_DEBUG, filename, __LINE__, ##__VA_ARGS__); \
} while (0)

#define INFO_LOG(format, ...) do {                                                                          \
    char time_str[80] = {0};                                                                                \
    GET_CURRENT_TIME(time_str);                                                                             \
    char *filename = strrchr(__FILE__, '/') + 1;                                                                 \
    printf("%s [%s] [%s:%d]:" format "\n", time_str, LOG_LEVEL_INFO, filename, __LINE__, ##__VA_ARGS__); \
} while (0)

#define WARN_LOG(format, ...) do {                                                                          \
    char time_str[80] = {0};                                                                                \
    GET_CURRENT_TIME(time_str);                                                                             \
    char *filename = strrchr(__FILE__, '/') + 1;                                                                 \
    printf("%s [%s] [%s:%d]:" format "\n", time_str, LOG_LEVEL_WARN, filename, __LINE__, ##__VA_ARGS__); \
} while (0)

#define ERR_LOG(format, ...) do {                                                                           \
    char time_str[80] = {0};                                                                                \
    GET_CURRENT_TIME(time_str);                                                                             \
    char *filename = strrchr(__FILE__, '/') + 1;                                                                 \
    printf("%s [%s] [%s:%d]:" format "\n", time_str, LOG_LEVEL_ERROR, filename, __LINE__, ##__VA_ARGS__); \
} while (0)

void print_rect_buff_uint8(uint8_t* buffer, int width, int height, int stride);

#endif 